package vcp.client.GUI.mvc.controller;

import vcp.client.GUI.events.ValidationDescriptionEvent;
import vcp.client.GUI.mvc.model.UIAbstractModel;
import vcp.client.GUI.mvc.model.UICheckInModel;
import vcp.client.GUI.mvc.view.UIAbstractView;
import vcp.client.GUI.mvc.view.UICheckInView;
import vcp.client.interfaces.listeners.IValidationListener;
import vcp.client.utility.Common.UserNotification;
import vcp.client.utility.UtilityHelper;
import vcp.enums.PopUpMessageType;
import vcp.enums.Screen;
import vcp.enums.SiteEnum;

/**
 * 
 * @author VCP team
 *         <p>
 *         check in controller
 *         </p>
 * 
 * @see UICheckInModel
 * @see UICheckInView
 * @see IValidationListener
 */
public class UICheckInController extends UIAbstractController implements IValidationListener
{
	/**
	 * Application online data source
	 */
	private final UICheckInModel model;

	/**
	 * Application online panel
	 */
	private final UICheckInView view;

	/**
	 * 
	 * @param model
	 *            : Online data source
	 * @param view
	 *            : Online GUI panel
	 */
	public UICheckInController ( UICheckInView view, UICheckInModel model )
	{
		super(Screen.CHECK_IN);
		this.model = model;
		this.view = view;
		this.setupListeners();
	}

	// ****************************************************************************************************************************
	// UIAbstractController methods
	// ****************************************************************************************************************************
	@Override
	public UIAbstractView getView ()
	{
		return this.view;
	}

	@Override
	public UIAbstractModel getModel ()
	{
		return this.model;
	}

	@Override
	protected void setupListeners ()
	{
		super.setupListeners();
		this.view.setValidationListener(this);
	}

	// ****************************************************************************************************************************
	// IControllerModelDelegate methods
	// ****************************************************************************************************************************
	@Override
	public void uploadDataContext ( Object dataContext )
	{
		if ( dataContext instanceof SiteEnum )
		{
			SiteEnum siteEnum = (SiteEnum) dataContext;
			this.model.setSite(siteEnum);
			this.view.setSiteName(this.model.getSite().toString());
		}
	}

	// ****************************************************************************************************************************
	// IValidationListener methods
	// ****************************************************************************************************************************
	@Override
	public void onValidationRequest ( ValidationDescriptionEvent validationEvent )
	{
		final Integer userid = validationEvent.getID();
		final Integer carid = validationEvent.getCarID();

		if ( UtilityHelper.getUtilityHelperInstance().isParamsNotNull(userid, carid) )
		{
			this.model.verifyCheckInInfo(userid, carid);
		}
		else
		{
			this.parentDelegate.showPopUpMessage(UserNotification.WRONG_DATA, PopUpMessageType.ERROR);
		}
	}
}
